package com.kangyi.app.mapper;

import com.kangyi.app.annotation.AutoFill;
import com.kangyi.dto.ForgotPasswordDTO;
import com.kangyi.entity.User;
import com.kangyi.enumeration.OperationType;
import com.kangyi.vo.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@Mapper
public interface UserMapper {

    @Select("select * from user where phone = #{phone}")
    User getUser(String phone);

    @Insert("insert into user(phone,password,status,create_time,create_user,update_time,update_user) " +
            "values (#{phone},#{password},#{status},#{createTime},#{createUser},#{updateTime},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void insert(User user);

    @Update("update user set password = #{newPassword} where phone = #{phone}")
    @AutoFill(value = OperationType.UPDATE)
    void resetPassword(ForgotPasswordDTO forgotPasswordDTO);

    @Select("select * from user where id = #{currentId}")
    UserVO selectById(Integer currentId);

    @AutoFill(value = OperationType.UPDATE)
    void update(User user);

    List<UserVO> getUsersByIds(List<Integer> userIds);
}
